﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.BLL.Order;
using ECommerce.Model.Order;
using Jzy.Core.Common;
using ECommerce.Common;

namespace ECommerce.Web.Site
{
    public partial class MemberOrder : SitePage
    {
        private ECOrderBO Order
        {
            get
            {
                return ECOrderBO.Instance<ECOrderBO>();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            base.CheckLogin();
            if (!IsPostBack)
            {
                BindView();
               
            }
        }

        private void BindView()
        {
            PagerSetting setting = new PagerSetting();
            setting.PageSize = int.MaxValue;
            setting.Where = "MemberID=" + SiteSession.MemberID;
            setting.OrderBy = "InputTime desc";
            List<ECOrderInfo> list = Order.GetList(setting);
            rpt.DataSource = list;
            rpt.DataBind();
        }


        protected string GetPayState(object payMode, object payState)
        {           
            if ((int)payMode == (int)PayMode.货到付款)
            {
                return PayMode.货到付款.ToString();
            }
            else
            {
                return ((PayState)(int)payState).ToString();
            }
        }
       

        protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink lnkPay = e.Item.FindControl("lnkPay") as HyperLink;
                ECOrderInfo orderInfo = e.Item.DataItem as ECOrderInfo;
                if (orderInfo.PayMode == (int)PayMode.在线支付 && (orderInfo.PayState == (int)PayState.未支付 || orderInfo.PayState == (int)PayState.支付失败))
                {
                    lnkPay.Visible = true;
                }
                else
                {
                    lnkPay.Visible = false;
                }
            }
        }
    }
}